<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>填写订单</title>
    <link rel="stylesheet" href="../../../css/aui.css" />
    <link rel="stylesheet" href="../../../css/iconfont/iconfont.css">
    <link rel="stylesheet" href="../../../script/widget/pickout/css/pickout.css">
    <link rel="stylesheet" href="../../../css/index/hotel/filtrate.css">
    <link rel="stylesheet" href="../../../css/index/hotel/book.css" />
    <style>
        .hotel-name-title {
            position: absolute;
            bottom: 0;
            left: 0;
            background: rgba(0, 0, 0, 0.2);
        }

        .box-shodow {
            background: #fff;
            box-shadow: 2px 3px 5px #d0d0d0;
        }

        .customer ul,
        .travle-purpose,
        .contact ul,
        .customer:last-child ul .aui-list-item:last-child {
            background: none !important;
        }

        .aui-list:after,
        .aui-list:before {
            height: 0 !important;
        }

        .consignee-item .aui-list-item-arrow:before {
            top: 48% !important;
        }
    </style>
</head>

<body style="background: #f7f7f7;">
    <form action="" id="orderSubmit">
        <div class="aui-content height-240" style="position:relative;overflow: inherit;">
            <!--头部start-->
            <header class="aui-bar aui-bar-nav" style="background: transparent;position:fixed;top:0;" id="header">
                <a class="aui-pull-left aui-btn">
                    <span class="aui-iconfont aui-icon-left" style="" onclick="closeWin();"></span>
                </a>
                <div class="aui-title">
                    <span class="">填写订单</span>
                </div>
                <a class="aui-pull-right aui-btn aui-btn-outlined" style="border: 0;" onclick="backHome();">
                    <span class="aui-iconfont aui-icon-home"></span>
                </a>
            </header>
            <!--头部end-->
            <div class="width-100" style="position:absolute;top:0">
                <div>
                    <img width="100%" height="240" class="hotel-img" src="" alt="">
                </div>
            </div>
            <div class="aui-content hotel-name-title width-100 height-30 text-lh-30 text-fw" style="color:#fff;">
                <div class="height-auto ml-10 hotel-name"></div>
            </div>
        </div>
        <div style="clear: both;"></div>
        <div class="aui-content box-shodow padding-10" style="clear: both;">
            <div class="mt-10 text-fw">
                <span class="stay-time">5月23日 - 5月25日</span><span class="stay-days">&nbsp;&nbsp;&nbsp;</span>
            </div>
            <div class="mt-10">
                <span class="text-fw room-type"></span>
                <span class="float-right mr-10 text-fw font-warning price" style="font-size: 1.1rem;"></span>
            </div>
            <div class="mt-10 clear-float font-warning change-rule" style=""></div>
        </div>

        <!-- 顾客信息 -->
        <div class="aui-content box-shodow padding-10 mt-30" id="customer-container" style="clear: both;padding-bottom:0;">
            <div class="aui-card-list-header" style="border-bottom: 1px solid #dddddd">
                <div><span class="aui-text-danger text-fw"> 入住人</span></div>
            </div>
            <!-- <div class="aui-card-list-content">
                <ul class="aui-list aui-media-list">
                    <li class="aui-list-item aui-list-item-middle">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-inner aui-list-item-arrow" style="">
                                <div style="width:50%;" class="float-left">
                                  <div class="aui-list-item-text">
                                      <div class="aui-list-item-title aui-font-size-14">AUI</div>
                                  </div>
                                  <div class="aui-list-item-text" style="justify-content: unset;">
                                    <span>免审</span>
                                    <span class="is-sms" data-userId="">发送短信</span>
                                    <label>
                                      <input type="hidden" name="" value="1" class="is-sms-input" data-userId="">
                                    </label>
                                  </div>
                                </div>
                                <div style="margin-top: 10px;" class="float-right">
                                    请选择成本中心
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div> -->
        </div>

        <!-- 住店要求等数据 -->
        <div class="aui-content box-shodow padding-10 mt-30" style="clear: both;">
            <div class="aui-card-list-content ml-10" style="">
                <ul class="aui-list aui-media-list require">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media" style="width: 1.3rem;padding-right: 0;">
                                <i class="aui-iconfont aui-icon-date"></i>
                                <!--<img src="../../../image/hotel/head.png" class="aui-img-round aui-list-img-sm">-->
                            </div>
                            <div class="aui-list-item-inner aui-list-item-arrow" style="padding: 0;padding-right: 1.5rem;">
                                <span style="margin-top: 13px;" class="float-left">到店时间</span>
                                <select name="trip_order[earlies_arrival_time]" class="float-right width-auto" style="color:blue;margin-top: 3px;width: 50px;" id="earlies_arrival_time">

                                    </select>
                                <!--<span class="float-right" style="font-size: 15px;margin-top: 3px;">12：00</span>-->
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media" style="width: 1.3rem;padding-right: 0;">
                                <i class="aui-iconfont aui-icon-home"></i>
                                <!--<img src="../../../image/hotel/head.png" class="aui-img-round aui-list-img-sm">-->
                            </div>
                            <div class="aui-list-item-inner aui-list-item-arrow" style="padding: 0;padding-right: 1.5rem;">
                                <span style="margin-top: 13px;" class="float-left">房间数量</span>
                                <select name="trip_order[room_numbers]" class="float-right width-auto" style="color:blue;margin-top: 3px;" id="room_num">
                                  </select>
                                <!--<span class="float-right" style="font-size: 15px;margin-top: 3px;">12</span>-->
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle aui-hide" style="padding-left: 0;">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media" style="width: 1.3rem;padding-right: 0;">
                                <i class="aui-iconfont aui-icon-edit"></i>
                                <!--<img src="../../../image/hotel/head.png" class="aui-img-round aui-list-img-sm">-->
                            </div>
                            <div class="aui-list-item-inner aui-list-item-arrow">
                                <span>住房要求</span>
                                <span class="float-right" style="font-size: 15px;margin-top: 3px;">无要求</span>
                                <input type="hidden" value="无要求" name="trip_order[require]">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-media" style="width: 1.3rem;padding-right: 0;">
                                <i class="aui-iconfont aui-icon-cert"></i>
                                <!--<img src="../../../image/hotel/head.png" class="aui-img-round aui-list-img-sm">-->
                            </div>
                            <div class="aui-list-item-inner aui-margin-r-10">
                                <span>订单总额</span>
                                <span class="float-right font-warning price text-fw" id="all-price" style="font-size: 15px;margin-top: 3px;"></span>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 负责审批的成本中心 -->
        <div class="aui-content box-shodow padding-10 mt-30 approved-cost-center" style="clear: both;">
            <div class="aui-card-list-header" style="border-bottom: 1px solid #dddddd">
                <div><span class="aui-text-danger text-fw"> 请选择负责审批的成本中心</span></div>
            </div>
            <div class="aui-card-list-content ml-10" style="">
                <ul class="aui-list aui-media-list" id="approve-cost">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;">
                        <div class="aui-list-item-input ml-10 aui-list-item-arrow" style="position:relative;">
                            <select name="trip_policy[cost_center_id]" class="end-cost">
                              <option value="-1" selected>-- 请选择 --</option>
                            </select>
                        </div>
                        <div class="approve-cost-name aui-padded-l-5 aui-text-danger"></div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 违规 -->
        <div class="aui-content box-shodow padding-10 mt-30 is-violation" style="display:none;">
            <div class="aui-card-list-header" style="border-bottom: 1px solid #dddddd;display: block;">
                <div><span class="aui-text-danger text-fw"> 政策违规</span></div>
                <div class="reason"><span class="aui-text-danger text-fw" style="text-indent: 2em;"></span></div>
            </div>
            <div class="aui-card-list-content ml-10" style="">
                <ul class="aui-list aui-media-list" id="">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 0;">
                        <div class="aui-list-item-input ml-10 aui-list-item-arrow" style="position:relative;">
                            <select name="trip_order[violation_reason]" class="">
                                    <option value="-1" selected>-- 请选择 --</option>
                                    <option value="标准内酒店满房">标准内酒店满房</option>
                                    <option value="标准内酒店远离出差办事地点">标准内酒店远离出差办事地点</option>
                                    <option value="会议或培训等活动指定酒店">会议或培训等活动指定酒店</option>
                                    <option value="节假日或展会期间房价上涨">节假日或展会期间房价上涨</option>
                                    <option value="酒店季节性价格调整">酒店季节性价格调整</option>
                                    <option value="为客户预订">为客户预订/招待客户</option>
                                    <option value="两人同住分摊房费">两人同住分摊房费</option>
                                    <option value="超标费用自行承担">超标费用自行承担</option>
                                    <option value="标准内酒店不满足特殊需求">标准内酒店不满足特殊需求</option>
                                    <option value="标准内酒店无法操作预付">标准内酒店无法操作预付</option>
                                    <option value="港澳/海外酒店，不受政策限制">港澳/海外酒店，不受政策限制</option>
                                </select>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 联系人 -->
        <div class="aui-content box-shodow padding-10 mt-30" style="clear: both;">
            <div class="aui-card-list-header" style="border-bottom: 1px solid #dddddd">
                <div><span class="aui-text-danger text-fw"> 联系人</span></div>
            </div>
            <div class="aui-card-list-content ml-10" style="">
                <ul class="aui-list aui-media-list contact" id="contact">
                    <li class="aui-list-item aui-list-item-middle consignee-item" style="padding-left: 0;">
                        <div class="aui-media-list-item-inner" data-userId="">
                            <div class="aui-list-item-media" style="width: 2.3rem;">
                                <img src="../../../image/head_portrait.png" class="aui-img-round aui-list-img-sm">
                            </div>
                            <div class="aui-list-item-inner aui-list-item-arrow contact-content">
                                <span class="contact-name"></span>
                                <input type="hidden" class="contact-id" name="trip_order[consignee_id]" value="">
                                <span class="float-right contact-mobile" style="font-size: 15px;"></span>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 担保 -->
        <div class="aui-content box-shodow padding-10 mt-30 guarantee aui-hide" style="clear: both;">
            <div class="aui-card-list-header" style="border-bottom: 1px solid #dddddd;">
                <div><span class="aui-text-danger text-fw">担保规则</span></div>
            </div>
            <div class="aui-card-list-content ml-10 mt-10" style="">
                <ul class="aui-list contact aui-form-list">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-inner">
                                <span>担保首日费用5月23日 12:00前可退，5月23日 12:00前可改</span>
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray">
                                行用卡类型
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <select>
                                        <option>招商银行</option>
                                        <option>民生银行</option>
                                        <option>光大银行</option>
                                    </select>
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray">
                                信用卡卡号
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray">
                                CVV2码
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-fw">
                                有效期
                            </div>
                            <div class="aui-list-item-input ml-10 aui-list-item-arrow">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray">
                                持卡人姓名
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray" style="width: 50%;">
                                持卡人手机号码
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray" style="width: 60%;">
                                持卡人省份证号码
                            </div>
                            <div class="aui-list-item-input ml-10">
                                <input type="text" placeholder="">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- 出行目的 -->
        <div class="aui-content box-shodow padding-10 mt-30" style="clear: both;">
            <div class="aui-card-list-header" style="">
                <ul class="aui-list contact aui-form-list travle-purpose" style="width: 100%;">
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-label text-c-gray" style="line-height: 2.3rem;">
                                出行目的
                            </div>
                            <div class="aui-list-item-input ml-10 aui-list-item-arrow">
                                <select name="trip_order[trip_cause]" class="width-auto float-right" style="margin-right: 15px;">
                                        <option value="商务谈判/拜访">商务谈判/拜访</option>
                                        <option value="商务考察">商务考察</option>
                                        <option value="学习/培训">学习/培训</option>
                                        <option value="技术支持">技术支持</option>
                                        <option value="会展/展务">会展/展务</option>
                                        <option value="奖励/旅游">奖励/旅游</option>
                                        <option value="-1">其他</option>
                                    </select>
                            </div>
                        </div>
                    </li>
                    <li class="aui-list-item aui-list-item-middle" style="padding-left: 5px;">
                        <div class="aui-list-item-inner">
                            <div class="aui-list-item-input">
                                <input type="text" name="trip_order[trip_cause_memo]" placeholder="备注(出行目的为其他时必填)">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <div class="aui-content" style="text-align: center;padding:1rem;">
            <input class="aui-btn aui-btn-warning mt-30 mb-50 booking" style="width: 80%;display:none" type="submit" value="提交">
            <div class="aui-btn aui-btn-primary aui-btn-block" id="sub_order">提交订单</div>
        </div>
    </form>
    <div id="sms" class="aui-hide">
        <div class='aui-list-item-input' style='padding: 15px;'>
            <label><input class='aui-radio' type='radio' name='smsdemo1' checked value='1' style="height:1.2rem;min-height:1.2rem;border-radius: 1.2rem;vertical-align: bottom;"> 发送短信</label>
            <label><input class="aui-radio" type="radio" name="smsdemo1" value="0" style="height:1.2rem;min-height:1.2rem;border-radius: 1.2rem;vertical-align: bottom;"> 不发送短信</label>
        </div>
    </div>
</body>
<!-- 顾客 -->
<script type="text/template" id="customer_tpl">
    {{ for(let i=0;i
    <it.length;i++){ }} <div class="aui-card-list-content customer">
        <ul class="aui-list aui-media-list">
            {{? it[i].is_non_staff == 1}}
            <li class="aui-list-item aui-list-item-middle person" data-userId="{{= it[i].travels_id }}">
                {{??}}
                <li class="aui-list-item aui-list-item-middle person" data-userId="{{= it[i].user_id }}">
                    {{?}}
                    <div class="aui-media-list-item-inner">
                        <div class="aui-list-item-inner aui-list-item-arrow" style="">
                            {{? it[i].is_non_staff == 1}}
                              <input type="hidden" value="{{= it[i].travels_id }}" name="trip_users[{{= i }}][travel_user_id]" class="id">
                              <input type="hidden" name="trip_users[{{= i }}][travel_user_type]" value="0">
                            {{??}}
                              <input type="hidden" value="{{= it[i].user_id }}" name="trip_users[{{= i }}][travel_user_id]" class="id">
                              <input type="hidden" name="trip_users[{{= i }}][travel_user_type]" value="1">
                            {{?}}
                            <input type="hidden" value="{{= it[i].user_name }}" class="name" name="trip_users[{{= i }}][travel_user_name]">
                            <input type="hidden" value="{{= it[i].mobile }}" name="trip_users[{{= i }}][travel_user_mobile]">
                            <div style="width:50%;" class="float-left">
                                <div class="aui-list-item-text">
                                    <div class="aui-list-item-title aui-font-size-14">{{= it[i].user_name}}</div>
                                </div>
                                <div class="aui-list-item-text sms-content" style="justify-content: unset;">
                                    {{? it[i].is_non_staff == 1}} {{= it[i].approval_type}}
                                    <span class="is-sms" data-userId="{{= it[i].travels_id }}">发送短信</span>
                                    <label>
                                    <input type="hidden" name="trip_users[{{= i }}][message_confirm]" value="1" class="is-sms-input" data-userId="{{= it[i].travels_id }}">
                                  </label> {{??}} {{= it[i].approval_type}}
                                    <span class="is-sms" data-userId="{{= it[i].user_id }}">发送短信</span>
                                    <label>
                                    <input type="hidden" name="trip_users[{{= i }}][message_confirm]" value="1" class="is-sms-input" data-userId="{{= it[i].user_id }}">
                                  </label> {{?}}
                                </div>
                            </div>
                            <div style="margin-top: 10px;" class="float-right select-cost cost-click{{= it[i].user_id }}" data-userId="{{= it[i].user_id }}">
                                <span>请选择成本中心</span>
                                <input type="hidden" value="" name="trip_users[{{= i }}][cost_center_id]" class="cost-center-id">
                            </div>
                        </div>
                    </div>
                </li>
        </ul>
        </div>
        {{ } }}
</script>

<script type="text/javascript" src="../../../script/extend/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../../script/aui/api.js"></script>
<script type="text/javascript" src="../../../script/aui/aui-dialog.js"></script>
<script type="text/javascript" src="../../../script/config.js"></script>
<script type="text/javascript" src="../../../script/common.js"></script>
<script type="text/javascript" src="../../../script/extend/formSerializeObj.js"></script>
<script type="text/javascript" src="../../../script/extend/doT.min.js"></script>
<script>
    //基本查询参数
    let hotelData,
        //酒店信息
        hotelDetail,
        //房型信息
        ratePlanData,
        //差旅政策
        policyData,
        //入住人
        custormer,
        //常用出行人
        passenger,
        //出行人数
        people_num,
        //审批类型
        approve_type;
        //是否违规
        let isViolation = $api.getStorage('is_violation');
    apiready = function() {
        api.parseTapmode();
        //设置沉浸式
        var header = $api.byId('header');
        $api.fixStatusBar(header);
        //滚动条事件
        $(window).scroll(function() {
            if ($(window).scrollTop() > 50) $api.css(header, "background: #3CB0D6;");
            else $api.css(header, "background: transparent;");
        });
        hotelData = $api.strToJson($api.getStorage("hotel_data"));
        //酒店信息
        hotelDetail = $api.strToJson($api.getStorage("checked_room_detail"));
        //房型信息
        ratePlanData = $api.strToJson($api.getStorage("checked_rate_plans"));
        //差旅政策
        policyData = $api.strToJson($api.getStorage("trip_policy"));
        //入住人
        custormer = $api.getStorage("travel_people");
        //常用出行人  不属于公司的人
        passenger = $api.getStorage('common_staff');

        // console.log($api.jsonToStr(hotelData));
        // console.log($api.jsonToStr(hotelDetail));
        // console.log($api.jsonToStr(ratePlanData));
        // console.log(custormer);
        //基本信息
        baseInfo();
        //到店时间
        selectShopTime();
        //入住人列表
        custormerList();
        //联系人
        getConsigneeList();
        //判断因公因私
        if (Number(policyData.order_type) === 1) {
            $(".approved-cost-center").remove();
            $(".guarantee").remove();
            $('.is-violation').remove();
        } else {
            //担保
            if (ratePlanData.GuaranteeRuleIds === 0 || !ratePlanData.GuaranteeRuleIds) {
                $(".guarantee").remove();
            } else {
                $(".guarantee").removeClass("guarantee");
            }
        }

        //判断是否为违规
        if (isViolation == 'true') {
            //违规
            if (hotelData.isOpenTc === 1) $(".is-violation .reason").empty().html("超过预定限定金额:￥"+hotelData.policy_max_money+"元，已超标!");
            else $(".is-violation .reason").empty().html(policyData.check_msg);
            $(".is-violation").show();
        } else {
            $(".is-violation").hide();
        }
        //选择联系人
        $(".contact").on("click", ".consignee-item", function() {
            let _this = $(this);
            let userId = _this.attr("data-userId");
            openWin('contact_list_win', '../common/contact_list_win.html');
        });
        //选择发送短信
        $("#customer-container").on("click", ".sms-content", function() {
            let _this = $(this);
            let userId = _this.attr("data-userId");
            var dialog = new auiDialog({});
            let html = $("#sms").html();
            dialog.alert({
                title: "是否发送短信",
                msg: html,
                buttons: ['确定', '取消']
            }, function(ret) {
                if (ret) {
                    var checked = $("[name=smsdemo1]:checked").val();
                    if (ret.buttonIndex == 1) {
                        //1发送   2不发送
                        let checked = $("[name=smsdemo1]:checked").val();
                        let arr = ["不发送短信", "发送短信"];
                        _this.find(".is-sms").html(arr[checked]);
                        _this.find(".is-sms-input").val(checked);
                    }
                }
            })
        });
        //选择成本中心
        var selectCostId;
        $("#customer-container").on("click", ".select-cost", function() {
            selectCostId = $(this).attr("data-userId");
            openWin("cost_center", "../common/cost_center_frm.html",{user_id : selectCostId});
        });

        //监听成本中心选择完成
        api.addEventListener({
            name: 'selectCostEvt'
        }, function(ret, err) {
            let uniqueArr = [];
            $(".cost-click" + selectCostId).find("span").html(ret.value.cost_name);
            $(".cost-click" + selectCostId).find("input").val(ret.value.cost_id);

            $("#approve-cost select").empty().append('<option value="-1" selected>-- 请选择 --</option>');
            let center = $('.customer .select-cost');
            for (var i = 0; i < center.length; i++) {
                let id = center.eq(i).find('input').val();
                let name = center.eq(i).find('span').text();
                //防止重复
                if ($.inArray(id, uniqueArr) === -1) {
                    uniqueArr.push(id);
                    $("#approve-cost select").append("<option value='" + id + "'>" + name + "</option>");
                }
            }

        });
        //监听联系人选择完成
        api.addEventListener({
            name: 'contactUser'
        }, function(ret, err){
            $(".contact-content .contact-mobile").html(ret.value.contact_mobile);
            $(".contact-content .contact-name").html(ret.value.contact_name);
            $(".contact-content .contact-id").val(ret.value.contact_id);
        });

        //根据房间数量改变总价
        $("#room_num").change(function () {
            let num = $(this).val();
            // console.log((ratePlanData.TotalRate/hotelData.date_amount) * num);
            //判断是否违规
            if (hotelData.isOpenTc === 1 ) {
                // console.log((ratePlanData.TotalRate/hotelData.date_amount) * num);
                // console.log(JSON.stringify(hotelData));
                // console.log(hotelData.policy_max_money);
                if(((ratePlanData.TotalRate/hotelData.date_amount) * num) > hotelData.policy_max_money){
                    isViolation = 'true';
                    //判断是否允许违规预定
                    if (!policyData.is_allow_violation_book) {
                        let roomNum = Math.ceil(custormer.split(',').length/2);
                        $(this).val(roomNum);
                        $alert('当前差旅政策不允许违规预定!');
                        return false;
                    } else {
                        $(".is-violation .reason").empty().html("超过预定限定金额:￥"+hotelData.policy_max_money+"元，已超标!");
                        $('.is-violation').show();
                    }
                } else {
                    $('.is-violation').hide();
                    isViolation = 'false';
                }
                $api.setStorage('is_violation', isViolation);
            }
            $("#all-price").html("￥" + (num * ratePlanData.TotalRate).toFixed(2));
        });

        //审批的成本中心
        $("#approve-cost select").change(function() {
            let cost_id = $(this).val();
            if (cost_id == -1) {
                $(".approve-cost-name").empty().hide();
                $toast("请选择正确的成本中心");
                return false;
            }
            let param = {};
            param.url = Config.common.getApproveInfo;
            param.data = {
                cost_center_id: cost_id
            };
            approveCost(param);
        });

        $('#sub_order').click(function() {
            $('.booking').click();
        });

        //提交订单
        $("#orderSubmit").submit(function(e) {
            e.preventDefault();
            let param = $(this).serializeJson();
            //不是因私的情况
            if (policyData.order_type != 1) {
                let customer_cost = $(".cost-center-id");
                for (let i = 0; i < customer_cost.length; i++) {
                    if (!customer_cost.eq(i).val()) {
                        $toast("请选择顾客成本中心");
                        return false;
                    }
                }
                //判断是否选择审批的成本中心
                if (Number(param['trip_policy[cost_center_id]']) === -1) {
                    $toast("请选择负责审批的成本中心");
                    return false;
                }
            }

            //判断出行原因
            if (Number(param["trip_order[trip_cause]"]) === -1) {
                if ($.trim(param["trip_order[trip_cause_memo]"]).length < 1) {
                    $toast("请填写出行目的");
                    $("[name='trip_order[trip_cause_memo]']").focus();
                    return false;
                }
                param["trip_order[trip_cause]"] = $.trim(param["trip_order[trip_cause_memo]"]);
            }
            //联系人验证
            if(!param['trip_order[consignee_id]']) {
                $toast('请选择联系人');
                return false;
            }

            //判断是否为违规
            if (Number(policyData.order_type) != 1) {
                if (isViolation === 'true') {
                    if(Number(param["trip_order[violation_reason]"]) === -1){
                        $toast("当前订单已违规,请选择违规原因");
                        return false;
                    }
                } else {
                    $('.is_violation').remove();
                }
            }

            delete param["trip_order[trip_cause_memo]"];
            param["trip_order[memo1]"] = "";

            const customerItem = $(".customer .person");
            let customerName = '',
                customerIds = '';
            for (let i = 0; i < customerItem.length; i++) {
                customerName += $.trim(customerItem.eq(i).find("input.name").val()) + ",";
                customerIds += customerItem.eq(i).find("input.id").val() + ",";
            }
            //去除最后一个字符 ,
            customerName = customerName.substr(0, customerName.length - 1);
            customerIds  = customerIds.substr(0, customerIds.length - 1);
            let formData = {
                /*
                    差旅信息
                */
                "trip_policy[order_self]"     : policyData.order_type,
                "trip_policy[policy_id]"      : "",
                "trip_policy[is_violation]"   : "",
                /*
                    订单信息
                */
                "trip_order[arrival_time]"    : hotelData.arrival_date.replace(/\//g, "-"),
                "trip_order[departure_time]"  : hotelData.departure_date.replace(/\//g, "-"),
                "trip_order[city]"            : hotelData.city_name,
                "trip_order[hotelid]"         : hotelData.hotel_id,
                "trip_order[room_type_id]"    : ratePlanData.RoomTypeId,
                "trip_order[rate_plan_id]"    : ratePlanData.RatePlanId,
                "trip_order[pay_ment_type]"   : ratePlanData.PaymentType,
                "trip_order[guarantee]"       : ratePlanData.GuaranteeRuleIds,
                "trip_order[room_price]"      : (ratePlanData.TotalRate/hotelData.date_amount).toFixed(2),
                "trip_order[create_module]"   : "company",
                "trip_order[credit_info]"     : "",
                //出行人名称
                "trip_order[trip_users]"      : customerName,
                //出行人id
                "trip_order[trip_users_ids]"  : customerIds,
                "trip_order[violation_reason]": "",
                "trip_policy[cost_center_id]" : '',
                "trip_order[oa_number]"       : '',
                "trip_policy[is_policy_collect]" : 0
            };
            //正常流程
            if (parseInt(policyData.order_type) === -1) {
                formData["trip_policy[order_self]"] = policyData.order_self;
            }

            let customerRequire = "";
            if (param.check_need) {
                customerRequire += param.check_need + ",";
            }
            if (!customerRequire) {
                customerRequire += "无要求";
            }

            formData["trip_order[require]"] = customerRequire;

            //因公
            if (Number(policyData.order_type) != 1) {
                formData["trip_policy[policy_id]"]     = policyData.policy_id;
                formData["trip_policy[is_violation]"]  = isViolation;
                formData["trip_policy[is_policy_collect]"]  = hotelData.isOpenTc;
                if (hotelData.isApply == 1) {
                    formData["trip_order[oa_number]"]  = hotelData.oaNumber;
                }
            }

            let request = {};
            request.url = Config.hotel.hotelSubmitOrder;
            //合并数据
            request.data = $.extend(formData, param);
            ajax(request, function(ret) {
                // console.log($api.jsonToStr(ret));
                if (ret.code !== 1) {
                    $alert(ret.msg);
                } else {
                    $alert(ret.msg, function(index) {
                        $api.rmStorage("trip_policy");
                        $api.rmStorage("checked_room_detail");
                        $api.rmStorage("checked_rate_plans");
                        $api.rmStorage("travel_people");
                        api.openWin({
                            name: 'order_success_win',
                            url: './../common/order_success_win.html',
                            slidBackEnabled:false,
                            pageParam: {
                                price: $("#all-price").html().substring(1,$("#all-price").html().length)
                            }
                        });
                    });
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    };

    //基本信息
    function baseInfo() {
        //酒店图片
        $(".hotel-img").attr("src", hotelDetail.coverImage);
        //酒店名称
        $(".hotel-name").html(hotelDetail.HotelName);
        //日期匹配
        // console.log($api.jsonToStr(hotelData));
        var arrival_date = hotelData.arrival_date.split("-");
        $(".stay-time").html(arrival_date[1] + "月" + arrival_date[2] + "日 - ");
        var departure_date = hotelData.departure_date.split("-");
        $(".stay-time").append(departure_date[1] + "月" + departure_date[2] + "日");
        //入住总天数
        $(".stay-days").html("&nbsp;&nbsp;&nbsp;入住&nbsp;" + hotelData.date_amount + "晚");
        //酒店价格
        // console.log(ratePlanData.TotalRate);
        // console.log(hotelData.date_amount);
        $(".price").html("￥" + Math.ceil((ratePlanData.TotalRate/hotelData.date_amount)));
        //房间类型
        $(".room-type").html(ratePlanData.RatePlanName);
        //退房规则
        $(".change-rule").html(ratePlanData.ChangeRule);
    }
    //选择最早到店时间
    function selectShopTime() {
        let date = new Date();
        let currentDate = date.getDate(); //获取当前日期
        let targetDate = new Date(hotelData.arrival_date.replace(/-/g, '/')).getDate();
        let hours = 12;
        let arrivalTime = $("#earlies_arrival_time");
        if (targetDate == currentDate) {
            hours = date.getHours() + 1;
        }
        for (let i = hours; i < 24; i++) {
            i = i < 10 ? '0' + i : i; //如果是10点之前就给时间前补零
            arrivalTime.append("<option value='" + i + ":00'>" + i + ":00</option>");
            //次日
            if (i === 23) {
                for (let j = 0; j <= 6; j++) {
                    j = '0' + j; //如果是10点之前就给时间前补零
                    arrivalTime.append("<option value='" + j + ":00'>" + j + ":00</option>");
                }
            }
        }
    }
    //入住人列表
    function custormerList() {
        let param = {};
        if (!passenger) passenger = [];
        param.url = Config.common.getTravelUser;
        if (policyData.order_type == 1) {
            param.data = {
                staffIds: custormer,
                noStaffIds: Array.isArray(passenger) ? '' : passenger
            };
        } else {
            param.data = {
                'staffIds': custormer
            };
        }
        ajax(param, function(data) {
          console.log(JSON.stringify(data));
            if (data.code === 1) {
              people_num = data.count;//出行人数
              if (people_num == 1) {
                approve_type = data.data[0].approval_name;//审批类型
              }
                const approveType = ["免审", "出行审批", "违规审批"];
                for (let i = 0; i < data.data.length; i++) {
                    if (policyData.order_type == 1) {
                        data.data[i].approval_type = '';
                    } else {
                        data.data[i].approval_type = approveType[data.data[i].approval_type] + ',';
                    }
                }
                let tpl = document.getElementById("customer_tpl").innerHTML;

                $("#customer-container").append(doT.template(tpl)(data.data));
                if (policyData.order_type == 1) {
                    $('.select-cost').remove();
                }
                //处理房间数量
                const travelLen = $("#customer-container").find(".customer").length;
                var currIndex = 0;
                for (let i = 1; i <= travelLen; i++) {
                    if (i >= travelLen / 2) {
                        currIndex += 1;
                        if(currIndex == 1) {
                          $("#all-price").html("￥" + (i * ratePlanData.TotalRate).toFixed(2));
                        }
                        $("#room_num").append("<option value='" + i + "'>" + i + "</option>");
                    }
                }
            } else {
                $toast(data.msg);
                return false;
            }
        });
    }
    //负责审批的成本中心
    function approveCost(param) {
        console.log(JSON.stringify(param));
        ajax(param, function(data) {
            if (data.code === 1) {
                console.log(JSON.stringify(data));
                //审批人ids
                let approve_id = [],
                    approve_name = [];
                //审批信息
                let approve_msg = "当前订单不需要审批";
                // console.log(data.data);
                $.each(data.data, function(key, val) {
                    approve_id[key] = val.user_id;
                    approve_name[key] = val.user_name;
                });
                if (isViolation === 'true') {
                    if ($.inArray(approve_id, custormer.split(",")) === -1) {
                        approve_msg = '当前订单需要审批,审批人：' + approve_name.toString();
                    }
                }
                //判断违规情况下一个人的审批情况
                if (isViolation == 'true' && people_num == 1 && approve_type == '免审') {
                     approve_msg = '当前订单不需要审批';
                }
                $(".approve-cost-name").text(approve_msg);
            } else {
                $toast(data.msg);
                return false;
            }
        })
    }
    //联系人
    function getConsigneeList() {
        let param = {};
        param.url = Config.common.getContact;
        param.data = {
            'user_id': $api.getStorage("user_id")
        };
        ajax(param, function(ret) {
            if (ret.code === 1) {
                $(".contact-content .contact-mobile").html(ret.data[0].contact_mobile);
                $(".contact-content .contact-name").html(ret.data[0].contact_name);
                $(".contact-content .contact-id").val(ret.data[0].id);
            } else {
                $toast(ret.msg);
            }
        });
    }
    /**
     * 日期相减
     * @param selectDay1 开始日期
     * @param selectDay2 结束日期
     * @returns {number}
     */
    function dayMinus(selectDay1, selectDay2) {
        //当年计算
        let selectDaysOne = currentTotalDays(selectDay1); //选择日期的第几天
        let selectDaysTwo = currentTotalDays(selectDay2); //选择日期的第几天
        if (selectDaysOne < selectDaysTwo) {
            $alert('日期错误！');
        }
        //跨年计算
        let selectYear = new Date(selectDaysOne);
        let thisYear = new Date(selectDaysTwo);
        let result;
        if (selectYear.getFullYear() > thisYear.getFullYear()) {
            //跨年
            result = isLeapYear(thisYear.getFullYear()) + currentTotalDays(selectDaysOne) - currentTotalDays(selectDaysTwo); //选中日期第几天+去年一共天数
        } else {
            //当年
            result = selectDaysOne - selectDaysTwo;
        }
        return result;
    }

    /**
     * 选中时间是一年中的第几天
     * @param selectDay
     * @returns {number}
     */
    function currentTotalDays(selectDay) {
        return Math.ceil((new Date(selectDay) - new Date(new Date(selectDay).getFullYear().toString())) / (24 * 60 * 60 * 1000));
    }

    /**
     * 判断年份是否为润年
     * @param {Number} year
     */
    function isLeapYear(year) {
        return (year % 400 === 0) || (year % 4 === 0 && year % 100 !== 0);
    }
</script>
</html>
